#pragma once

#include "Log.h"
#include <cassert>

#if defined __GNUC__ || defined __llvm__
/// LIKCLY 宏的封装, 告诉编译器优化,条件大概率成立
#define MYWEB_LIKELY(x) __builtin_expect(!!(x), 1)
/// LIKCLY 宏的封装, 告诉编译器优化,条件大概率不成立
#define MYWEB_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define MYWEB_LIKELY(x) (x)
#define MYWEB_UNLIKELY(x) (x)
#endif

/// 断言宏封装
#define MYWEB_ASSERT(x)                                                                \
    if (MYWEB_UNLIKELY(!(x))) {                                                        \
        MYWEB_LOG_ERROR(MYWEB_LOG_ROOT()) << "ASSERTION: " #x                          \
                                          << "\n";                                     \
        assert(x);                                                                     \
    }

/// 断言宏封装
#define MYWEB_ASSERT2(x, w)                                                            \
    if (MYWEB_UNLIKELY(!(x))) {                                                        \
        MYWEB_LOG_ERROR(MYWEB_LOG_ROOT()) << "ASSERTION: " #x                          \
                                          << "\n"                                      \
                                          << w                                         \
                                          << "\n";                                     \
        assert(x);                                                                     \
    }

